<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ActionBase
 *
 * @author laimis
 */
class ActionBase {

    public $accountService;
    public $loginService;
    public $photoService;
    public $galleryService;
    public $account;
    public $isUserLogedIn = null;

    public function getAccount(){
        if($this->account == null){
            $this->setAccount();
        }
        return $this->account;
    }

    public function setAccount(){
        if($this->isUserLogedIn()){
            if($this->getAccountService() != null){
                $this->account = $this->accountService->getByName($_SESSION['userName']);
            }
        }
    }

    public function isUserLogedIn(){
        if($this->isUserLogedIn == null){
            if(isset ($_SESSION['user'],$_SESSION['is_loged'],$_SESSION['userName'])){
                if($_SESSION['is_loged'] === md5('SempleUserIsLogedIn')){
                    $this->isUserLogedIn = true;
                }
                if($this->getLoginService() != null){
                    $this->isUserLogedIn = $this->loginService->isUserExist($_SESSION['userName'],$_SESSION['user']);
                }
            }
        }
        return $this->isUserLogedIn;
    }

    public function getLoginService(){
        if($this->loginService == null){
            include_once LOGINSERVICE;
            $this->loginService = new LoginService();
        }
        return $this->loginService;
    }

    public function getAccountService(){
        if($this->accountService == null){
            include_once ACCOUNTSERVICE;
            $this->accountService = new AccountService();
        }
        return $this->accountService;
    }

    public function getPhotoService(){
        if($this->photoService == null){
            include_once PHOTOSERVICE;
            $this->photoService = new PhotoService();
        }
        return $this->photoService;
    }

    public function getGalleryService(){
        if($this->galleryService == null){
            include_once GALLERYSERVICE;
            $this->galleryService = new GalleryService();
        }
        return $this->galleryService;
    }

}
?>
